#include <iostream>
#include <vector>
#include <stack>
#include "TreeNode.h"
using namespace std;

// 未完成，待修改！

int largestRectangleArea(vector<int> &heights)
{
    stack<int> st;
    st.push(-1);
    heights.push_back(0);
    int res = 0;
    for (int i = 0; i < heights.size(); i++)
    {
        while (heights[i] < heights[st.top()])
        {
            int left = st.top();
            st.pop();
            res = max(res, heights[left] * (i - left));
        }
        st.push(i);
        printf("%d", heights[st.top()]);
    }
    return res;
}

int main()
{
    vector<int> heights = {2, 1, 5, 6, 2, 3};
    int res = largestRectangleArea(heights);
    return 0;
}